package com.steveproject.parttimeworktree.adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.squareup.picasso.Picasso;
import com.steveproject.parttimeworktree.App;
import com.steveproject.parttimeworktree.R;
import com.steveproject.parttimeworktree.entity.Part2MsgEntity;
import com.steveproject.parttimeworktree.utils.ScreenUtil;

import java.util.List;

public class Part2MsgAdapter extends BaseQuickAdapter<Part2MsgEntity, BaseViewHolder> {
    private Activity activity;
    private int spec;
    private int screenWidth;
    private int imgWidth;
    private int imgHeigh;

    public Part2MsgAdapter(Activity activity, List<Part2MsgEntity> newsList) {
        super(R.layout.item_part2_msg, newsList);
        this.activity = activity;
        screenWidth = ScreenUtil.getScreenWidth(activity);
        imgWidth = screenWidth - ScreenUtil.dip2px(App.getContext(), 40);
        imgHeigh=(imgWidth*256)/678;
        spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void convert(BaseViewHolder helper, Part2MsgEntity item) {


        TextView tv_1 = helper.getView(R.id.tv_1);
        TextView tv_2 = helper.getView(R.id.tv_2);
        TextView tv_3 = helper.getView(R.id.tv_3);


        ImageView img = helper.getView(R.id.img);//背景图
        TextView tv_title = helper.getView(R.id.tv_title);//标题
        TextView tv_money = helper.getView(R.id.tv_money);//money
        TextView tv_bm = helper.getView(R.id.tv_bm);//标题 item.getImgUrl()
        Picasso.with(activity).load(item.getImgUrl()).into(img);
        tv_title.setText(item.getTitle());
        tv_money.setText(item.getMoney() + item.getUnit());
        img.measure(spec, spec);
        //适配组件信息
        tv_title.measure(spec, spec);
        tv_money.measure(spec, spec);
        tv_bm.measure(spec, spec);
        int interval=(imgHeigh - tv_title.getMeasuredHeight() - tv_money.getMeasuredHeight() - tv_bm.getMeasuredHeight());



        LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) tv_1.getLayoutParams(); //取控件textView当前的布局参数 linearParams.height = 20;// 控件的高强制设成20
        linearParams.height =(interval*2)/7  ;// 控件的宽强制设成30
        tv_1.setLayoutParams(linearParams); //使设置好的布局参数应用到控件
        LinearLayout.LayoutParams linearParams2 = (LinearLayout.LayoutParams) tv_2.getLayoutParams(); //取控件textView当前的布局参数 linearParams.height = 20;// 控件的高强制设成20
        linearParams2.height = (interval)/7;// 控件的宽强制设成30
        tv_2.setLayoutParams(linearParams2); //使设置好的布局参数应用到控件
        LinearLayout.LayoutParams linearParams3 = (LinearLayout.LayoutParams) tv_3.getLayoutParams(); //取控件textView当前的布局参数 linearParams.height = 20;// 控件的高强制设成20
        linearParams3.height = (interval*2)/7;// 控件的宽强制设成30
        tv_3.setLayoutParams(linearParams3); //使设置好的布局参数应用到控件

    }
}
